package com.base.leetcode;

import com.base.dataStructure.stack.ArrayStack;

/**
 * @Author: hdhao
 * @Create: 2023/4/1 - 22:22
 * @Version: v1.0
 */
//使用两个栈实现队列
public class Leetcode232 {

    /*
    队列头     队列尾
    顶   底   底   顶
    s1             s2
     */
    ArrayStack<Integer> s1 = new ArrayStack<>(100);
    ArrayStack<Integer> s2 = new ArrayStack<>(100);
    public void push(int x){//向队列尾添加
        s2.push(x);
    }
    public int pop(){//从队列头移除
        if (s1.isEmpty()){
            while (!s2.isEmpty()){
                s1.push(s2.pop());
            }
        }
        return s1.pop();
    }
    public int peek(){
        if (s1.isEmpty()){
            while (!s2.isEmpty()){
                s1.push(s2.pop());
            }
        }
        return s1.peek();
    }

    public boolean empty(){
        return s1.isEmpty() && s2.isEmpty();
    }

}
